package com.dhcc.sds.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.dto.AnalysisCaseDto;
import com.dhcc.sds.busi.service.IAnalysisSdsMstaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 科室归集组报表统计页面入口
 * @author:sunyj
 * @date:2024年05月13日09:58:22
 * @Copyright: (c) DHCC All rights reserved.
 */
@Controller
@RequestMapping("${sys.backendPath}/analysis/sdslocgroup")
public class AnalysisSdsMstaLocGroupController {
    private String PREFIX = "/backend/sds/analysis/";

    @Autowired
    private IAnalysisSdsMstaService analysisSdsMstaService;

    @Autowired
    private ISdsQcentityService sdsQcentityService;

    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private ICdcHospitalService cdcHospitalService;

    @RequestMapping("")
    public String index(Model model) {
        JSONArray departGroupMap = sdsCommonService.getDepartGroupMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("departGroupMap",departGroupMap);
        model.addAttribute("entityMap",entityMap);
        return PREFIX + "sdslocgroup.html";
    }

    @RequestMapping("selectSdsLocGroupTable")
    @ResponseBody
    public Object selectSdsLocGroupTable(@RequestParam Map<String, Object> params) {
        return analysisSdsMstaService.selectSdsLocGroupTable(params);
    }

    @RequestMapping("toLocCase")
    public String toLocCase(@RequestParam Map<String, Object> map,Model model) {

        model.addAttribute("startDateV", map.get("startDate"));
        model.addAttribute("endDateV", map.get("endDate"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        model.addAttribute("desc",map.get("desc"));
        return PREFIX + "loccase.html";
    }

    @RequestMapping("selectSdsDocTable")
    @ResponseBody
    public Object selectSdsDocTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        //List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        //params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsDocTable(params);
    }

    @RequestMapping("/locOrGroup")
    public String locOrGroup(Model model) {
        //获取部门信息
        JSONArray officeMap = cdcHospitalService.getOfficeMap();
        JSONArray departGroupMap = sdsCommonService.getDepartGroupMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("officeMap",officeMap);
        model.addAttribute("departGroupMap",departGroupMap);
        model.addAttribute("entityMap",entityMap);
        return PREFIX + "analysisreportlocorgroup.html";
    }

    /**
     * @Description: 查询上报计数据-科室或科室组
     * @Title: getReportLocOrGroup
     * @param params
     * @return: Object
     * @author: sunyj
     * @date:2024年05月28日 上午11:23:02
     */
    @RequestMapping("getReportLocOrGroup")
    @ResponseBody
    public Object getReportLocOrGroup(@RequestParam Map<String, Object> params) {
        return this.analysisSdsMstaService.getReportLocOrGroup(params);
    }

    /**
     * 跳转上报分析二级页面
     */
    @RequestMapping("locgroupcase")
    public String toLocGroupCase(@RequestParam Map<String, Object> params,Model model ){
        model.addAttribute("key", params.get("key"));
        model.addAttribute("desc",params.get("desc"));
        model.addAttribute("analysisGrain", params.get("analysisGrain"));
        model.addAttribute("depart",params.get("depart"));
        model.addAttribute("entityType",params.get("entityType"));
        model.addAttribute("startDate",params.get("startDate"));
        model.addAttribute("endDate",params.get("endDate"));
        model.addAttribute("doctor",params.get("doctor"));
        model.addAttribute("dateType",params.get("dateType"));
        return PREFIX + "locgroupcase.html";
    }
    /**
     *  查询上报分析二级页面病人数据
     */
    @RequestMapping("selectCaseList")
    @ResponseBody
    public Object selectCaseList(@RequestParam Map<String,Object> params){
        Page<AnalysisCaseDto> page = new PageFactory<AnalysisCaseDto>().defaultPage();
        List<AnalysisCaseDto> result = this.analysisSdsMstaService.selectLocGroupCaseList(page, params);
        page.setRecords((List<AnalysisCaseDto>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }
}
